//
//  CZEmoticonFooterView.swift
//  git
//
//  Created by 徐 鹏超 on 16/4/16.
//  Copyright © 2016年 徐 鹏飞. All rights reserved.
//

import UIKit

enum EmoticonType:Int{
    case Recent = 1000      //最近表情
    case Default = 1001     // 默认表情
    case Emoji = 1002       // Emoji表情
    case Lxh = 1003         // 浪小花表情
}

protocol CZEmoticonFooterViewDelegate:NSObjectProtocol{
    func emoticonToolBarButtonDidSelected(type:EmoticonType)
}




class CZEmoticonFooterView: UIView {
    
    weak var delegate:CZEmoticonFooterViewDelegate?

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        addSubview(recentButton)
        addSubview(defaultButton)
        addSubview(emojiButton)
        addSubview(lxhButton)
        
        // 设置约束
        recentButton.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.height.equalTo(self.snp_height)
            
            make.width.equalTo(defaultButton.snp_width)
            
        }
        
        defaultButton.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self.snp_top)
            make.height.equalTo(self.snp_height)
            
            make.left.equalTo(recentButton.snp_right)
            make.right.equalTo(emojiButton.snp_left)
            
            make.width.equalTo(emojiButton.snp_width)
        }
        
        emojiButton.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self.snp_top)
            make.height.equalTo(self.snp_height)
            
            make.left.equalTo(defaultButton.snp_right)
            make.right.equalTo(lxhButton.snp_left)
            
        }
        
        lxhButton.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(self.snp_top)
            make.height.equalTo(self.snp_height)
            
            make.right.equalTo(self.snp_right)
            make.width.equalTo(emojiButton.snp_width)
            
        }

    }
    
    //MARK:--按钮方法
    func buttonClick(button:UIButton){
        for subview in subviews{
            let subButton = subview as! UIButton
            
            subButton.selected = false
        }
        button.selected = true
        
        delegate?.emoticonToolBarButtonDidSelected(EmoticonType(rawValue: button.tag)!)
    }
    
    
    
    //懒加载
    lazy var recentButton:UIButton = {
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_normal"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_selected"), forState: UIControlState.Selected)
        
        button.tag = EmoticonType.Recent.rawValue
        
        button.setTitle("最近", forState: UIControlState.Normal)
        
        button.addTarget(self, action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
    
    lazy var defaultButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_normal"), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_selected"), forState: UIControlState.Selected)
        
        button.tag = EmoticonType.Default.rawValue
        
        button.setTitle("默认", forState: UIControlState.Normal)
        
        button.addTarget(self , action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
    
    lazy var emojiButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_normal"), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_selected"), forState: UIControlState.Selected)
        
        button.tag = EmoticonType.Emoji.rawValue
        
        button.setTitle("emoji", forState: UIControlState.Normal)
        
        button.addTarget(self , action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()
    
    lazy var lxhButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_normal"), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "compose_emotion_table_selected"), forState: UIControlState.Selected)
        
        button.tag = EmoticonType.Lxh.rawValue
        
        button.setTitle("浪小花", forState: UIControlState.Normal)
        
        button.addTarget(self , action: "buttonClick:", forControlEvents: UIControlEvents.TouchUpInside)
        
        return button
    }()

    

}
